/*
 * Proja - project management software
 * Copyright (C) 2012  Oleg Kasian
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

package org.proja.core.entity;

import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity(name = "Project")
@Table(name = "PROJECTS")
public class Project extends AbstractEntity {
    
    @Id
    @SequenceGenerator(name = "ProjectSeq", sequenceName = "PROJECTS_SEQ")
    @GeneratedValue(generator = "ProjectSeq")
    @Column(name = "ID", updatable = false)
    private Long id;

    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "DESCRIPTION")
    private String description;

    @ManyToOne(cascade = CascadeType.DETACH)
    @JoinColumn(name = "OWNER", updatable = false, nullable = false)
    private User owner;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "CATEGORY_ID")
    private ProjectCategory category;

    @Column(name = "IS_OPEN")
    private Boolean open;

    @Column(name = "CREATED_ON", nullable = false, updatable = false)
    @Temporal(TemporalType.DATE)
    private Date createdOn;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "project")
    private Set<Module> modules;

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(final Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(final String description) {
        this.description = description;
    }

    public Set<Module> getModules() {
        return modules;
    }

    public void setModules(final Set<Module> modules) {
        this.modules = modules;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(final User owner) {
        this.owner = owner;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(final Date createdOn) {
        this.createdOn = createdOn;
    }

    public ProjectCategory getCategory() {
        return category;
    }

    public void setCategory(final ProjectCategory category) {
        this.category = category;
    }

    public Boolean getOpen() {
        return open;
    }

    public void setOpen(final Boolean open) {
        this.open = open;
    }

}
